package com.ruoyi.rocky.controller;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.rocky.domain.PcSysNotice;
import com.ruoyi.rocky.service.PcSysNoticeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 系统通知Controller
 *
 * @date 2024-04-26
 */
@Slf4j
@Validated
@RestController
@RequestMapping("/pcNotice")
@AllArgsConstructor
@Api(tags = "通知管理")
public class PcSysNoticeController extends BaseController {
    @Autowired
    private PcSysNoticeService pcSysNoticeService;

    /**
     * 查询系统通知列表
     */
    @ApiOperation(value = "查询系统通知列表")
    @GetMapping("/list")
    public TableDataInfo list(PcSysNotice pcSysNotice) {
        startPage();
        List<PcSysNotice> list = pcSysNoticeService.selectPcSysNoticeList(pcSysNotice);
        return getDataTable(list);
    }

//    /**
//     * 导出系统通知列表
//     */
//    @ApiOperation(value = "导出系统通知列表")
//    @PostMapping("/export")
//    public void export(HttpServletResponse response, PcSysNotice pcSysNotice) {
//        List<PcSysNotice> list = pcSysNoticeService.selectPcSysNoticeList(pcSysNotice);
//        ExcelUtil<PcSysNotice> util = new ExcelUtil<PcSysNotice>(PcSysNotice.class);
//        util.exportExcel(response, list, "系统通知数据");
//    }

    /**
     * 获取系统通知详细信息
     */
    @ApiOperation(value = "获取系统通知详细信息")
    @GetMapping(value = "/{noticeId}")
    public R getInfo(@PathVariable("noticeId") Long noticeId) {
        return R.ok(pcSysNoticeService.selectPcSysNoticeByNoticeId(noticeId));
    }

    /**
     * 新增系统通知
     */
    @ApiOperation(value = "新增系统通知")
    @PostMapping
    public R add(@RequestBody PcSysNotice pcSysNotice) {
        return R.ok(pcSysNoticeService.insertPcSysNotice(pcSysNotice));
    }

    /**
     * 修改系统通知
     */
    @ApiOperation(value = "修改系统通知")
    @PutMapping
    public R edit(@RequestBody PcSysNotice pcSysNotice) {
        return R.ok(pcSysNoticeService.updatePcSysNotice(pcSysNotice));
    }

    /**
     * 删除系统通知
     */
    @ApiOperation(value = "删除系统通知")
    @DeleteMapping("/{noticeIds}")
    public R remove(@PathVariable Long[] noticeIds) {
        return R.ok(pcSysNoticeService.deletePcSysNoticeByNoticeIds(noticeIds));
    }
}
